using System;
using System.Linq;
using System.Threading.Tasks;
using Sino.CarGoCome.Core;
using Sino.CarGoCome.Model;
using Sino.CapacityCloud.WebApi;

namespace Sino.CarGoCome.VirtualCoreData
{
    public class MockFriendService : IFriendService
    {
        static Random random = new Random((int)DateTime.Now.Ticks);
        public async Task<FriendListResponse> SearchFriendAsync(string keyword)
        {
            return new FriendListResponse() { Friends = VirtualData.VirtualData.Friends.Take(10).ForEach(f => f.RatingPoint = random.NextDouble() * 10).ToArray() };
        }

        public async Task<FriendListResponse> GetFriendsAsync()
        {
            return new FriendListResponse() { Friends = VirtualData.VirtualData.Friends.ForEach(f => f.RatingPoint = random.NextDouble() * 10).ToArray() };
        }

        public async Task<FriendInfoResponse> AddFriendAsync(string userId)
        {
            return new FriendInfoResponse() { Friend = SetRandmRatingPoint(VirtualData.VirtualData.Friends[0]) };
        }

        public async Task<VoidResponse> DeleteFriendAsync(string userId)
        {
            return new VoidResponse();
        }

        public async Task<FriendInfoResponse> GetFriendInfoAsync(string userId)
        {
            return new FriendInfoResponse() { Friend = SetRandmRatingPoint(VirtualData.VirtualData.Friends.FirstOrDefault(f => f.Id == userId)) };
        }

        private static Friend SetRandmRatingPoint(Friend f)
        {
            f.RatingPoint = random.NextDouble() * 10;
            return f;
        }
    }
}